<template>
  <div class="eRobot" v-loading="loading">
    <div class="wrap_top title">
      <img src="/img/ebot/ebot.png" alt="">
      <p>{{$t('eRobot.title')}}</p>
      <span @click="enterRobotFun">{{$t('eRobot.enterRobotBtn')}}</span>
    </div>
    <div class="item_wrap">
      <div class="item" v-for="(item, index) in funArray" :key="index">
        <img width="96" height="96" :src="item.img">
        <p class="item_title">{{item.hText}}</p>
        <p class="item_text">{{item.pText}}</p>
      </div>
    </div>  
    <form  name="xbotSubmit" :action="ebotUrl" method="post" style="display:none;" target="_blank">
      <input type="text" v-for="(val, key, index) in page" :name="key" :value="val" :key="index"><br>
      <input type="submit" value="提交" id="xbotSubmit">
    </form>
  </div>
</template>

<script>
export default {
  name: 'ebot',
  data () {
    return {
      loading: false,
      isHaveRobot: false,
      ebotUrl: '',
      page: [],
      funArray: [
        {hText: this.$t('eRobot.presale'), pText: this.$t('eRobot.presaleText'), img: '/img/ebot/presale.png'},
        {hText: this.$t('eRobot.onSale'), pText: this.$t('eRobot.onSaleText'), img: '/img/ebot/onSale.png'},
        {hText: this.$t('eRobot.aftermarket'), pText: this.$t('eRobot.aftermarketText'), img: '/img/ebot/aftermarket.png'},
        {hText: this.$t('eRobot.unattended'), pText: this.$t('eRobot.unattendedText'), img: '/img/ebot/unattended.png'},
        {hText: this.$t('eRobot.manMachine'), pText: this.$t('eRobot.manMachineText'), img: '/img/ebot/manMachine.png'},
        {hText: this.$t('eRobot.start'), pText: this.$t('eRobot.startText'), img: '/img/ebot/start.png'},
      ]
    }
  },
  methods: {
    enterRobotFun () {
      this.openXBot()
    },
    openXBot () {
      this.$store.dispatch('getRobotUrl', {}).then(res => {
        this.page = res.dict
        this.ebotUrl = res.dict.ebotUrl
        this.$nextTick(() => {
          document.xbotSubmit.submit()
        })
      })
    },
    // 获取机器人配置
    getRobotConfig () {
      let user = this.$store.state.session.user
      const data = {
        account: user ? user.account : ''
      }
      this.loading = true
      this.$store.dispatch('queryRobotEnter', data).then(res => {
        if (res.message.includes('haveRobot')) {
          this.btnText = this.$t('xrobot.enterRobot')
          this.isHaveRobot = true
        } else {
          this.btnText = this.$t('xrobot.freeTrial')
          this.isHaveRobot = false
        }
        this.loading = false
      })
    }
  },
  beforeMount () {
    this.getRobotConfig()
  }
}
</script>
<style lang="stylus" scoped>
  .eRobot
    padding 50px 80px 0px 70px
    height: calc(100vh - 73px);
    overflow-y: auto;
    .wrap_top
      display flex
      align-items center
      flex-direction column
      img
        width 480px
      p
        font-size 16px
        color rgba(22,22,22,1)
        line-height 16px
        margin  20px 0 40px
      span
        display inline-block
        padding 0 32px
        font-size 14px
        height 40px
        line-height 40px
        background #2A6AED
        color #fff
        border-radius 4px
        cursor pointer
    .wrap_top.title
      img
        width unset
    .item_wrap
      width 100%
      height 180px
      margin 26px 0px 50px 0px
      .item
        width 33%
        height 180px
        text-align center
        float left
        margin-bottom 50px
        .item_title
          font-size 14px
          color $cf-gray2
          margin 8px 0 4px
        .item_text
          font-size 12px
          color #595959
</style>